package com.bankcomm.ui.views;

import com.bankcomm.ui.BOCMainHome;
import com.rytong.tools.utils.Utils;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
/**
 * BCMTextField.java
 * @author cheng.l 2013-8-8 下午06:07:47
 */
public class BCMTextField extends EditText{
	
	private InputMethodManager inputManager_ = null;
	private BOCMainHome bv_;
	public BCMTextField(Context context) {
		super(context);
		bv_ = (BOCMainHome)context;
		init();
	}
	
	public BCMTextField(Context context, AttributeSet attrs) {
		super(context, attrs);
		bv_ = (BOCMainHome)context;
		init();
	}

	private void init() {
		//手机银行调用密码键盘
		if(null == inputManager_){
			inputManager_ = (InputMethodManager)bv_.getSystemService(Context.INPUT_METHOD_SERVICE);			
		}
	}

	@Override
	public boolean dispatchTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		this.requestFocus();
		inputManager_.hideSoftInputFromWindow(getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);
		if(event.getAction() == MotionEvent.ACTION_DOWN){
			if(Utils.keyDlg_ == null || !Utils.keyDlg_.isShowing()){
				Utils.keyDlg_ = null ;
				Utils.showInputWindow(bv_, this, bv_.mainView);						
			}
			return true;
		}
		return true;
	}

	@Override
	protected void onFocusChanged(boolean focused, int direction,
			Rect previouslyFocusedRect) {
		// TODO Auto-generated method stub
		if(focused){
			inputManager_.hideSoftInputFromWindow(getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);
		}
		super.onFocusChanged(focused, direction, previouslyFocusedRect);
	}

}
